package com.wanlian.router.ui.manage;


import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.smart.android.ui.BaseFragment;
import com.smart.android.widget.EmptyListTipLayout;
import com.wanlian.router.R;
import com.wanlian.router.bean.NetDevice;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Hyu on 2018/8/29.
 * Email: fvaryu@qq.com
 */
public class ManageFragment extends BaseFragment {

    @BindView(R.id.view_listview)
    ListView mListView;

    private EmptyListTipLayout mEmptyListTipLayout;
    private OnlineDeviceAdapter mOnlineDeviceAdapter;
    private List<NetDevice> mNetDevices;

    public static ManageFragment newInstance() {
        return new ManageFragment();
    }

    @Override
    protected int layout() {
        return R.layout.fragment_manage;
    }

    @Override
    protected void initUI(View view) {
        super.initUI(view);

        setTitle("路由管理");
        getTitleView().setTextColor(getColorById(R.color.white));
        getNavbar().setBackgroundColor(getColorById(android.R.color.transparent));

        setNextTitle("设置");
        setNextColor(R.color.white);
        setNextClickLisener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                redirectActivity(RouterSettingActivity.class);
            }
        });

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                redirectActivity(DeviceDetailActivity.class);
            }
        });
    }

    @Override
    protected void initData(View view) {
        super.initData(view);
        mNetDevices = new ArrayList<>();
        mListView.setAdapter(mOnlineDeviceAdapter = new OnlineDeviceAdapter(getActivity(), mNetDevices));


        mEmptyListTipLayout = new EmptyListTipLayout(getActivity(), mListView);
        mEmptyListTipLayout.setImageTipEmptyResId(R.drawable.image_empty_router);
        mEmptyListTipLayout.setTitleEmptyText("还没有设备连接~");
        mEmptyListTipLayout.showEmpty();
    }
}
